home *** CD-ROM | disk | FTP | other *** search
/ FM Towns: Free Software Collection 9 / FM Towns Free Software Collection 9.iso / t_os / tool / dc15 / main.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-11-16  |  3.0 KB  |  142 lines

  1. /****************************************************
  2.  
  3.             Document Chain   version 1.4
  4.                                 ALGO [TOOLS no.02]
  5.                                 
  6.                                 1994.02.14
  7.                                         
  8. ******************************************************/
  9. #include<stdio.h>
  10. #include<string.h>
  11. #include<dos.h>
  12. #include<direct.h>
  13. #include<ctype.h>
  14. #include<stdlib.h>
  15. #include"list.h"
  16. #include"chain.h"
  17.  
  18. #define        TRUE    (-1)
  19. #define        FALSE    0
  20. #define        VERSION        "ver 1.5"
  21. #define     DATE        "1994.02.22"
  22.  
  23. LIST        head;
  24. PARA        infile,outfile;
  25. int            size=65535;        /* ファイルのトータルサイズ (default)*/
  26. int            cnt=0;            /* ファイルカウンター            */
  27. FILE        *ofp;            /* 出力用のファイルポインター    */
  28. char        file[14];        /* ファイルネーム用バッファ     */
  29.  
  30.  
  31. void CmdAnalyse(char *st,PARA *pa); /* 作ったあとで _splitpathを使えば
  32.                                         いいことを知った... */
  33. void msg(void);
  34. void usage(void);
  35.  
  36. void main(int argc,char *argv[])
  37. {
  38.     int i,n,dmy;
  39.     char in_flag=FALSE,*p=NULL;
  40.     
  41.     if(argc==1){
  42.         usage();exit(0);
  43.     }
  44.     
  45.     for(i=1;i<argc;i++){
  46.         if((*p=*argv[i])=='-'){
  47.             *p=*(++argv[i]);
  48.             switch(toupper(*p)){
  49.             case    'D':/* 只今整備中(^^;) */
  50.                         break;
  51.             case    'S':size=atoi(++argv[i])*1024;
  52.                         if(size<1024*5 || size>1024*1024){
  53.                             fprintf(stderr,"サイズの指定に誤りがあります\n");
  54.                             exit(1);
  55.                         }
  56.                         break;
  57.             }
  58.         }else{
  59.             if(in_flag==FALSE){
  60.                 CmdAnalyse(argv[i],&infile);
  61.                 in_flag=TRUE;
  62.             }else{
  63.                 CmdAnalyse(argv[i],&outfile);
  64.             }
  65.         }
  66.     }
  67.     
  68.     msg();
  69.     printf("File size  %05d byte.\n",size);
  70.     printf("Make target file list");
  71.     n=MakeList(infile);
  72.     printf("(%03d targets).\n",n);
  73.     printf("Line count:");
  74.     for(i=0;i<n;i++)printf(".");    /* LHAの真似表示(^^; */
  75.     for(i=0;i<n;i++)printf("\b");    /* 同じく真似        */
  76.     LineCount();
  77.     printf("\n");
  78.     
  79.     _dos_setdrive(outfile.drive,(unsigned int *)&dmy);
  80.     if(outfile.path[0] != '\0')
  81.         if (_chdir(outfile.path)==ERR){
  82.             printf("ディレクトリの指定が違います.");
  83.             exit(1);
  84.         }
  85.     while((cnt=SetFlag(size))!=0){
  86.         WriteOpenName(file);
  87.         if((ofp=fopen(file,"w"))==NULL){
  88.             fprintf(stderr,"Fine open error.'%s'",file);
  89.             exit(1);
  90.         }
  91.         printf("Create '%s' \n",file);
  92.         MakeIndex(cnt);
  93.         Chain(cnt);
  94.         fclose(ofp);
  95.         ClearFlag();
  96.     }
  97. }
  98.  
  99.  
  100. void CmdAnalyse(char *st,PARA *pa)
  101. {
  102.     char *p,pbuf[40];
  103.     unsigned int drv;
  104.     
  105.     
  106.     if((p=strchr(st,':'))!=NULL) {
  107.         pa->drive=toupper(*(p-1))-'A'+1;
  108.         st=p+1;
  109.     }else{
  110.         _dos_getdrive(&drv);
  111.         pa->drive=drv;
  112.     }
  113.     
  114.     if((p=strrchr(st,'\\'))!=NULL){
  115.         if(p==st){
  116.             strcpy(pa->path,"\\\0");
  117.             st++;
  118.         }else{
  119.             *p='\0';
  120.             strcpy(pa->path,st);
  121.             st=p+1;
  122.         }
  123.     }else{
  124.         _getcwd(pbuf,40);
  125.         strcpy(pa->path,&pbuf[2]);
  126.     }
  127.     strcpy(pa->file,st);
  128. }
  129.  
  130. void msg(void)
  131. {
  132.     printf("<<Document Chain %s>>  [TOOLS NO.02] ALGO\n",VERSION);
  133. }
  134.  
  135. void usage(void)
  136. {
  137.     msg();
  138.     printf("   usage: run386 dc <option> <target file> <output file>\n");
  139.     printf("   option ... -sxx  一つの分割ファイルのファイルの大きさ\n");
  140.     printf("                    単位はkb。省略時は64kb固定。\n");
  141. }
  142.